import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class BeautifulStrings {
	
	class ValueComparator implements Comparator<Character> {

	    Map<Character, Integer> base;
	    public ValueComparator(Map<Character, Integer> base) {
	        this.base = base;
	    }

	    // Note: this comparator imposes orderings that are inconsistent with equals.    
	    public int compare(Character a, Character b) {
	        if (base.get(a) >= base.get(b)) {
	            return -1;
	        } else {
	            return 1;
	        } // returning 0 would merge keys
	    }
	}
	
	public static void main(String argv[]) throws Exception{
		BeautifulStrings bs = new BeautifulStrings();
		BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		File resultfile = new File("output.txt");
		
		if (!resultfile.exists()) {
			resultfile.createNewFile();
		}
		FileWriter fw = new FileWriter(resultfile);
		BufferedWriter bw = new BufferedWriter(fw);
		
		
	    try {
	        String line = br.readLine();
	        int m = Integer.parseInt(line);
	        for(int i = 1; i<=m ; i++) {
	        	line = br.readLine();
	        	bw.write("Case #"+i+": "+bs.convert(line));
	        	if (m!=i) bw.newLine();
	        }
	    } finally {
	        br.close();
	        bw.close();
	    }
	}
	
	private int convert(String aLine) {
		HashMap<Character,Integer> map = new HashMap<Character,Integer>();
		for(int i=0; i<aLine.length() ; i++) {
			Character ch = aLine.charAt(i);
			if (!Character.isLetter(aLine.charAt(i))) {
				continue;
			} else
				ch = Character.toLowerCase(ch);
			if (map.containsKey(ch)) {
				map.put(ch, map.get(ch)+1);
			} else
				map.put(ch, 1);
		}
		ValueComparator bvc =  new ValueComparator(map);
		TreeMap<Character,Integer> sorted_map = new TreeMap<Character, Integer>(bvc);
		sorted_map.putAll(map);
		Integer result = 0;
		int count = 26;
		for(Integer value : sorted_map.values()) {
			result += value*count;
			count--;
		}
		
		return result;
	}
}
